package com.chenwc.util;

import com.alibaba.fastjson2.JSONObject;
import com.chenwc.util.fileutil.ReadFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.HashMap;

/**
 * 术语翻译及常用词语翻译
 *
 * @author chenwc
 * @package com.chenwc.util
 * @project wso2-sinicization
 * @date 2024/5/25
 */
public class LoadTerminology {
    private static final Logger log = LoggerFactory.getLogger(LoadTerminology.class);

    /**
     * 获取术语翻译及常用词语翻译，并把所有key转小写
     *
     * @return hashmap
     */
    public static HashMap<String, String> getTerminology() {
        HashMap<String, String> terminology = new HashMap<>();

        JSONObject tempJson = JSONObject.parseObject(getJsonFile());
        for (String key : tempJson.keySet()) {
            terminology.put(key.toLowerCase(), tempJson.getString(key));
        }
        return terminology;
    }

    /**
     * 读取json文件
     *
     * @return json文件字符串
     */
    public static String getJsonFile() {
        File pathFile = new File("1.txt");
        String path = pathFile.getAbsolutePath().replace("1.txt", "");
        File file = new File(path + "src\\main\\resources\\terminology.json");
        return ReadFile.readFile(file);
    }
}
